package io.github.wanggit.antrpc.client.spring;

import io.github.wanggit.antrpc.client.monitor.report.ZipkinAllMethodTracing;
import io.github.wanggit.antrpc.commons.bean.SerialNumberThreadLocal;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CallerProxyMethodInterceptor implements MethodInterceptor {
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy)
            throws Throwable {
        try {
            SerialNumberThreadLocal.get();
            return methodProxy.invokeSuper(o, objects);
        } finally {
            SerialNumberThreadLocal.clean();
            ZipkinAllMethodTracing.cleanTracing();
        }
    }
}
